package toledo.post;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;

import toledo.rest.UserToCourse;

public class AddUserToCourseServlet extends HttpServlet
{
	private static final long serialVersionUID=1L;

	public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException
	 {
		 String course_id = req.getParameter(UserToCourse.COURSE_ID);
		 String user_id = req.getParameter(UserToCourse.USER_ID);
		 Entity e = new Entity(UserToCourse.DATABASE);
		 e.setProperty(UserToCourse.COURSE_ID,course_id);
		 e.setProperty(UserToCourse.USER_ID,user_id);
		 
		 DatastoreServiceFactory.getDatastoreService().put(e);
		 
		 resp.sendRedirect("database.jsp");
	 }
}
